package eu.telecombretagne.rsm.protocol.test;

import eu.telecombretagne.rsm.base.entity.AltBitEmitterEntity;
import eu.telecombretagne.rsm.base.entity.AppEmitterEntity;
import eu.telecombretagne.rsm.base.entity.NetworkReaderEmitterEntity;
import eu.telecombretagne.rsm.base.entity.NetworkWriterEmitterEntity;
import eu.telecombretagne.rsm.base.entity.TimerEntity;
import eu.telecombretagne.rsm.base.event.*;
import eu.telecombretagne.rsm.gui.NameConsts;
import eu.telecombretagne.rsm.gui.frames.DesktopFrame;

public class Emetteur {
	
	private NetworkReaderEmitterEntity networkReaderEmitterEntity;
	private NetworkWriterEmitterEntity networkWriterEmitterEntity;
	private TimerEntity timerEntity;
	private AltBitEmitterEntity altBitEmitterEntity;
	private AppEmitterEntity appEmitterEntity;
	
	
	public Emetteur(){
		EventChannel ec = new EventChannel();
		
		networkReaderEmitterEntity = new NetworkReaderEmitterEntity(ec);
		networkReaderEmitterEntity.start();
		
		networkWriterEmitterEntity = new NetworkWriterEmitterEntity(ec);
		networkWriterEmitterEntity.start();
		
		try {
			Thread.sleep (10);
		}
		catch (InterruptedException ie) {
			DesktopFrame.writeLogError(NameConsts.EMETTEURMAIN + ie);
			System.exit(1);
		}
		
		timerEntity = new TimerEntity(ec);
		timerEntity.start();
		
		altBitEmitterEntity = new AltBitEmitterEntity(ec);
		altBitEmitterEntity.start();
		
		try {
			Thread.sleep (10);
		}
		catch (InterruptedException ie) {
			DesktopFrame.writeLogError(NameConsts.EMETTEURMAIN + ie);
			System.exit(1);
		}
		
		appEmitterEntity = new AppEmitterEntity(ec);
		appEmitterEntity.start();
	}
	
	public void stopEmetteur(){
		networkReaderEmitterEntity.stop();
		networkWriterEmitterEntity.stop();
		timerEntity.stop();
		altBitEmitterEntity.stop();
		appEmitterEntity.stop();
	}
}